<?php
//提现记录管理
namespace app\adminbackstage\model;

use think\facade\Db;
use think\Model;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Withdrawal extends Model{

    // 模型初始化
    protected static function init()
    {
        parent::init();
        //TODO:初始化内容
    }

    

    //提现记录信息
    public function withdrawalList($page=1,$num=10,$where){
        $list = $this::name('withdrawal')
        ->field('w.*,u.username,u.phone,u.addtime as uaddtime,u.num_su,u.wit_instr,u.wit_level')
        ->alias('w')
        ->leftJoin('user u','u.uid = w.uid')
        ->where($where)
        ->order('w.id', 'desc')
        ->limit(($page-1)*$num,$num)
        ->select();
        return $list;
   
    }
    
    //提现记录数
    public function withdrawalCount($where) {
//        $list = $this::name('withdrawal')
//        ->alias('w')
//        ->leftJoin('pg_user u','u.uid = w.uid')
//        ->where($where)
//        ->order('w.id', 'desc')
//        ->paginate();
//        $count = $list->total();
        return  $this::name('withdrawal')
        ->alias('w')
        ->leftJoin('user u','u.uid = w.uid')
        ->where($where)
        ->count();
//        return $count;
    }

    //获取提现总金额
    public function withdrawalSumToAccount($where){
        return $this::name('withdrawal')
            ->alias('w')
            ->leftJoin('user u','u.uid = w.uid')
            ->where($where)
            ->sum('to_account');
    }

    //提现记录添加
    public  function withdrawalAdd(array $data){
        return self::create($data);
    }
    
    //提现信息变更
    public function withdrawalEdit($id,$update){
        $in = $this::update($update, ['id' => $id]);
        return $in;
    }
    
    public function withdrawalInfo($where){
        $info = $this::name('withdrawal')
        ->field('w.*,u.username,u.phone,u.num_su')
        ->alias('w')
        ->leftJoin('user u','u.uid = w.uid')
        ->where($where)
        ->find();
        return $info;
    }

  
}
